package com.huawei.appmarket.service.hifolder;

import android.app.Activity;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.startup.StartupResponse;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.framework.startevents.protocol.view.ShowTermsActivity;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.HashMap;
import java.util.Map;
import o.awo;
import o.ccx;
import o.cfw;
import o.cvt;
import o.BaseRequest;
import o.cvv;
import o.dij;
import o.diq;
import o.Logger;
import o.ContentManager;
import o.dqq;
import o.dqx;
import o.eab.c;
import o.eac;
import o.eod;
import o.eoi;
import o.eoj;
import o.eqn;
import o.eqp;
import o.eqq;

public class AgreementSignService extends Service {
    private c ˊ = new c(this) {
        final /* synthetic */ AgreementSignService ˋ;

        {
            this.ˋ = r1;
        }

        public void ॱ(eac o_eac) throws RemoteException {
            Logger.ˏ("AgreementSignService", "checkAgreementSign start");
            this.ˋ.ˏ = o_eac;
            this.ˋ.ˎ = eqp.ॱ();
            if (ccx.ॱ()) {
                Logger.ˏ("AgreementSignService", "Agreement is Sign");
                if (this.ˋ.ˏ != null) {
                    try {
                        Map hashMap = new HashMap();
                        hashMap.put("agreement_locale_sign_status", Boolean.valueOf(true));
                        this.ˋ.ˏ.ॱ(hashMap);
                        return;
                    } catch (RemoteException e) {
                        Logger.e("AgreementSignService", "checkAgreementSign RemoteException");
                        return;
                    }
                }
                return;
            }
            boolean ˎ = ccx.ˎ();
            Logger.ˏ("AgreementSignService", "Agreement isOobeSign = " + ˎ);
            if (ˎ) {
                eod.ˏ(ContentManager.getInstant().getContext(), new eoi(this) {
                    final /* synthetic */ AnonymousClass4 ˎ;

                    {
                        this.ˎ = r1;
                    }

                    public void ˎ(int i) {
                        Logger.ˏ("AgreementSignService", " checkAccountLogin " + i);
                        if (i == 0) {
                            this.ˎ.ˋ.ॱ();
                        } else {
                            this.ˎ.ˋ.ˏ();
                        }
                    }
                }, true);
            } else {
                this.ˋ.ˎ(false);
            }
            new dij(null, new a()).ˏ(new e());
        }
    };
    private String ˎ;
    private eac ˏ;

    class a implements awo {
        final /* synthetic */ AgreementSignService ˎ;

        private a(AgreementSignService agreementSignService) {
            this.ˎ = agreementSignService;
        }

        public void ˋ(boolean z) {
            Logger.ˎ("AgreementSignService", " isAgreeProGlobal=" + z);
            if (this.ˎ.ˏ != null) {
                try {
                    Map hashMap = new HashMap();
                    hashMap.put("agreement_click_event", Boolean.valueOf(z));
                    this.ˎ.ˏ.ॱ(hashMap);
                } catch (RemoteException e) {
                    Logger.e("AgreementSignService", "agreementSignCallback RemoteException");
                }
            }
        }
    }

    static class e extends diq {
        private e() {
        }

        public void ˋ(Activity activity) {
            super.ˋ(activity);
            Logger.ˎ("AgreementSignService", "AgreementSignServiceactivity is null send broadcast onUpgrade");
        }

        public void ॱ(Activity activity) {
            super.ॱ(activity);
            Logger.ˎ("AgreementSignService", "AgreementSignServiceactivity is null send broadcast onNotSign");
        }

        public void ˎ(Activity activity) {
            super.ˎ(activity);
            Logger.ˎ("AgreementSignService", "onSign");
        }
    }

    private void ˏ() {
        Logger.ˏ("AgreementSignService", "checkAppGalleryLogin start");
        eqq.ˋ().ˎ("AgreementSignService", new eqn(this) {
            final /* synthetic */ AgreementSignService ॱ;

            {
                this.ॱ = r1;
            }

            public void onResult(int i) {
                if (i == 202) {
                    Logger.ˏ("AgreementSignService", "checkAppGalleryLogin success!");
                    this.ॱ.ˋ(UserSession.getInstance().getHomeCountry());
                } else {
                    Logger.ˏ("AgreementSignService", "no login!");
                    this.ॱ.ˎ(false);
                }
                eoj.ˋ().ˊ("AgreementSignService");
            }
        });
        eod.ॱ(ContentManager.getInstant().getContext());
    }

    private void ˋ(String str) {
        Logger.ˏ("AgreementSignService", "checkCountry currentCountry = " + this.ˎ + ";changeCountry = " + str);
        if (TextUtils.isEmpty(str)) {
            ˎ(false);
        } else if (str.equals(this.ˎ)) {
            ˎ(true);
        } else {
            this.ˎ = str;
            ˎ(false);
        }
    }

    private void ॱ() {
        Logger.ˏ("AgreementSignService", "callFont start");
        new dqx(ContentManager.getInstant().getContext()).ˏ(new dqq.c(this) {
            final /* synthetic */ AgreementSignService ˏ;

            {
                this.ˏ = r1;
            }

            public void ˏ(String str) {
                Logger.ˏ("AgreementSignService", "getGrsUrls onGetUrl = " + str);
                if (TextUtils.isEmpty(str)) {
                    Logger.ˎ("AgreementSignService", "getGrsUrls fail!");
                    return;
                }
                cvt ˎ = cvv.ˎ();
                ˎ.ʼ(1);
                ˎ.ˋ(this.ˏ.ˎ);
                cfw.ˎ(ˎ, new IServerCallBack(this) {
                    final /* synthetic */ AnonymousClass5 ˋ;

                    {
                        this.ˋ = r1;
                    }

                    public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
                    }

                    public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                        if ((o_cvu instanceof cvv) && (responseBean instanceof StartupResponse)) {
                            cvv o_cvv = (cvv) o_cvu;
                            StartupResponse startupResponse = (StartupResponse) responseBean;
                            if (startupResponse.getResponseCode() != 0 || startupResponse.ॱᐝ() == null) {
                                this.ˋ.ˏ.ˎ(false);
                            } else if (startupResponse.getResponseType() == com.huawei.appgallery.serverreqkit.api.bean.ResponseBean.a.ˏ || o_cvv.ˏ() != 1) {
                                this.ˋ.ˏ.ˎ(false);
                            } else {
                                startupResponse.ˎ(o_cvv);
                                this.ˋ.ˏ.ˋ(startupResponse.ॱᐝ());
                            }
                        }
                    }
                });
            }
        });
    }

    private void ˎ(boolean z) {
        if (this.ˏ != null) {
            try {
                Map hashMap = new HashMap();
                hashMap.put("agreement_oobe_sign_status", Boolean.valueOf(z));
                hashMap.put("agreement_sign_country", this.ˎ);
                if (!z) {
                    hashMap.put("agreement_pending_intent", ˎ());
                }
                this.ˏ.ॱ(hashMap);
            } catch (RemoteException e) {
                Logger.e("AgreementSignService", "agreementSignCallback RemoteException");
            }
        }
    }

    public IBinder onBind(Intent intent) {
        Logger.ˏ("AgreementSignService", "AppGalleryInitService onBind");
        return this.ˊ;
    }

    private PendingIntent ˎ() {
        Context ˋ = ContentManager.getInstant().getContext();
        Intent intent = new Intent(ˋ, ShowTermsActivity.class);
        intent.putExtra("view_type", 1);
        intent.putExtra("service_type", 99);
        return PendingIntent.getActivity(ˋ, 0, intent, HwAccountConstants.FLAG_TRANS_NAVIGATION_BAR);
    }
}
